package com.example.campusproject.adapter;

import com.example.campusproject.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.*;

public class HMBSTListAdapter extends BaseItemProvider {
    private AbilitySlice context;
    private String[] infos;

    public HMBSTListAdapter(AbilitySlice context, String[] infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public int getCount() {
        return infos.length;
    }

    @Override
    public Object getItem(int i) {
        return infos[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    private class Holoder {
        Text text;

        public Holoder(Component component) {
            text = (Text) component.findComponentById(ResourceTable.Id_tv_hmbst_child);
        }
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        Component pc;
        Holoder holoder;
        if (component == null) {
            pc = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_ability_hmbst_item, null, false);
            holoder = new Holoder(pc);
            pc.setTag(holoder);
        } else {
            pc = component;
            holoder = (Holoder) pc.getTag();
        }
        holoder.text.setText(infos[i]);
        return pc;
    }
}
